#include <Application.hpp>
#include <Engine.hpp>

#include <CoreModule.hpp>
#include <RendererOESModule.hpp>


void Application::Init(IDK::Viewport viewport, String appPath)
{
	mEngine.Init(viewport);
	mEngine.GetCore()->SetDefaultResourcePath(appPath);

	mStates = CreateStates();
}

bool Application::Update(float dt)
{
	bool res = mStates->Update(mEngine, dt);
	mEngine.Update(dt);

	return res;
}

void Application::OnAction(const Action& evnt)
{
	mStates->OnAction(evnt);
}

void Engine::Init(IDK::Viewport viewport)
{
	mCore = Core::CoreModule::Create();
	mRenderer = Renderer::RendererOESModule::Create();

	mRenderer->SetViewport(viewport);

	mCore->OnStart();
	mRenderer->OnStart();
}

Engine::~Engine()
{
	mRenderer->SetViewport(NullPtr);
	mRenderer->OnFinish();
	mCore->OnFinish();
}

void Engine::Update(float dt)
{
	mCore->OnUpdate(dt);
	mRenderer->OnUpdate(dt);
}